package com.xianggu.Collection.demo;

import com.xianggu.Collection.map.MyHashMap;

import java.util.TreeSet;

/**
 * @author chengjy
 * @date 2025/4/3
 */
class HashMapDemo {
    public static void main(String[] args) {
        // 统计方法执行耗时
        long startTime = System.currentTimeMillis();


        MyHashMap<String, String> map = new MyHashMap<>();
        int count = 1000;
        for (int i = 0; i < count; i++) {
            map.put(String.valueOf(i), String.valueOf(i));
        }

        assert map.size() == count;

        // 判断值是否与存入的值相等
        for (int i = 0; i < count; i++) {
            assert map.get(String.valueOf(i)).equals(String.valueOf(i));
        }

        System.out.println("size : " + map.size());

        System.out.println("remove方法的返回值："+ map.remove("8"));;
        assert null == map.get("8");
        System.out.println("key 8 : value "+ map.get("8"));

        // 判断删除后是否相等
        assert map.size() == count - 1;
        System.out.println("size : " + map.size());


        System.out.println("耗时：" + (System.currentTimeMillis() - startTime) + "毫秒ms");

        System.out.println("打印map的元素 ======================");
        count = 0;

        TreeSet<Integer> set = new TreeSet<>();
        for (MyHashMap.Node node : map) {
            count++;
            System.out.println(node.getKey() + ": " + node.getValue());
            set.add(Integer.valueOf((String) node.getValue()));
        }
        System.out.println("排序后结果为： "+set);
        System.out.println("遍历的数量："+ set.size());
    }
}
